package zhtt.redis01;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @version 1.0
 * @Description
 * @Date 2016/10/15 18:30
 * @Author NICK
 */
@RestController
public class HelloController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("/hello")
    public String index() {
        // 保存字符串
        stringRedisTemplate.opsForValue().set("aaa", "111");
        String string = stringRedisTemplate.opsForValue().get("aaa");
        System.out.println(string);

        // 保存对象
        User01 user = new User01("超人", 20l);
        redisTemplate.opsForValue().set(user.getUsername(), user);

        user = new User01("蝙蝠侠", 30l);
        redisTemplate.opsForValue().set(user.getUsername(), user);

        user = new User01("蜘蛛侠", 40l);
        redisTemplate.opsForValue().set(user.getUsername(), user);
        User01 user1 = (User01)redisTemplate.opsForValue().get("超人");
        System.out.println(user1.getAge().longValue());
        System.out.println(((User01)redisTemplate.opsForValue().get("蝙蝠侠")).getAge().longValue());
        System.out.println(((User01)redisTemplate.opsForValue().get("蜘蛛侠")).getAge().longValue());

        return "Hello World";
    }
}